package com.befirefly.studentmanager.mapper;

import org.apache.commons.lang3.StringUtils;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.List;

/**
 * @Author: 八千里路云和月
 * @Date: 2021/2/8 11:50
 * @Description:
 */
public class AdminMapper {

    private static String path = StudentMapper.class.getClassLoader().getResource("").getPath() + "xml/manager.xml";
    private static Document document;

    static {
        try {
            System.out.println(path);
            document = new SAXReader().read(path);
        } catch (DocumentException e) {
            e.printStackTrace();
        }
    }

    public static String selectPasswordByUsername(String loginUsername) {
        Element rootElement = document.getRootElement();
        List<Element> elementList1 = rootElement.elements();
        for (Element element1 : elementList1) {
            String username = element1.element("username").getTextTrim();
            System.out.println(username);
            if (StringUtils.equals(username, loginUsername)) {
                return element1.element("password").getTextTrim();
            }
        }
        return null;
    }

}
